<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>Document</title>
    <link rel="shortcut icon" href="./images/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="../layui/css/layui.css">
    <style>
        body {
            padding: 20px 20px;
            background-color: #f2f3f5;
        }

        .userin {
            width: 500px;
        }
    </style>
</head>

<body>
    <div class="layui-card">
        <div class="layui-card-header">修改密码</div>
        <div class="layui-card-body">
            <form class="layui-form userin" action="">
                <div class="layui-form-item">
                    <label class="layui-form-label">原密码</label>
                    <div class="layui-input-block">
                        <input type="password" required lay-verify="required" autocomplete="off"
                            class="layui-input infoUser" placeholder="请输入原密码">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">新密码</label>
                    <div class="layui-input-block">
                        <input type="password" required lay-verify="required" placeholder="请输入新密码" autocomplete="off"
                            class="layui-input nickname">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">确认新密码</label>
                    <div class="layui-input-block">
                        <input type="password" required lay-verify="required" placeholder="请再次确认密码" autocomplete="off"
                            class="layui-input email">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="formDemo" type="submit">修改密码</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>

</body>

</html>
<script src="../layui/layui.js"></script>
<script src="../js/jquery-3.6.1.min.js"></script>
<script>


    $('.userin').on('submit', function (e) {
        e.preventDefault();
        if (!($('.nickname').val() == $('.email').val()))
            return layer.msg('确认密码不一致');
        $.ajax({
            type: 'post',
            url: '/my/updatepwd',
            headers: {
                'Authorization': localStorage.getItem('token')
            },
            data: {
                oldPwd: $('.infoUser').val(),
                newPwd: $('.email').val(),
            },
            success: (res) => {
                layer.msg(res.message);
                if (res.status == 0) {
                    localStorage.removeItem('token');
                    //强制f5
                    parent.location.reload();
                }

            }
        })
    })
</script>